script_enemy_main{

let effect1=0;
let object1=[];
let xscale1=0.01;
let yscale1=0.01;
let xscale2=0.01;
let yscale2=0.01;

let shot1=0;
let bullet1=[];

let angle1=0;
let angle2=0;
let angle3=rand(0,360);
let phase=0;
let size=0;
let color=0;
let hpos1=-GetClipMinX;
let hpos2=GetClipMaxX/2;
let phase2angle=rand(0,360);
let phase3shift=0;

let bgchange1=0;
let bgchange2=0;
let bgfade1=0;
let bgfade2=0;
let bgpicture1=0;
let bgpicture2=-384;
let bgchanged1=0;
let bgchanged2=0;

let character="Tomoko";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=42;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let move=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let enemylife=0;

let SEshots4=("\script\SoundEffects\shots4.wav");
let SElaserm3=("script\SoundEffects\laserm3.wav");
let SEmagics5=("\script\SoundEffects\magics5.wav");
let SElaserm2=("\script\SoundEffects\laserm2.wav");
let SEshotb7=("\script\SoundEffects\shotb7.wav");
let SEfocus=("script\SoundEffects\charge2.wav");
let SEimplode2=("script\SoundEffects\implode2.wav");
let SEexplode2=("script\SoundEffects\explode2.wav");

let EFwings=("\script\Images\OtherEffects\ButterflyWings.png");

let BG1=("\script\Images\BackgroundLayers\Tomoko7a.png");
let BG2=("\script\Images\BackgroundLayers\Tomoko7b.png");
let GRboss=("\script\Images\CharacterSprites\Tomoko.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsTomoko1.txt");

	LoadSE("\script\SoundEffects\shots4.wav");
	LoadSE("script\SoundEffects\laserm3.wav");
	LoadSE("\script\SoundEffects\magics5.wav");
	LoadSE("\script\SoundEffects\laserm2.wav");
	LoadSE("\script\SoundEffects\shotb7.wav");
	LoadSE("script\SoundEffects\charge2.wav");
	LoadSE("script\SoundEffects\implosion2.wav");
	LoadSE("script\SoundEffects\explosion2.wav");
		
	LoadGraphic("\script\Images\OtherEffects\ButterflyWings.png");

	LoadGraphic("\script\Images\BackgroundLayers\Tomoko7a.png");
	LoadGraphic("\script\Images\BackgroundLayers\Tomoko7b.png");
	LoadGraphic("\script\Images\CharacterSprites\Tomoko.png");

	LoadSE("script\SoundEffects\charge2.wav");
	LoadSE("script\SoundEffects\implode2.wav");
	LoadSE("script\SoundEffects\explde2.wav");

	SetScore(1000000);
	SetLife(1200);
	SetTimer(202);
	SetInvincibility(90);
	SetDamageRate(10,0); 
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(120,180,1);
	SetMovePosition02(cx,cy-100,50);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(64,64,64,64);

let weaken=1;
if(GetCommonData("BombOn")==0 && phase<4){ damagerate=4; }
if(GetCommonData("BombOn")==0 && phase>=4){ damagerate=16; }
if(GetCommonData("BombOn")==1){ damagerate=1; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("[The Meaning Of Life] ("~difficulty~")",spellcardnumber);
HealthBar();
Portrait(cutin,3);

if(time==60){
	loop(2){
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,GetX,GetY);
	ObjEffect_SetScale(effect1,xscale1,yscale1);
	ObjEffect_SetLayer(effect1,1); ObjEffect_SetTexture(effect1,EFwings); ObjEffect_SetRenderState(effect1,ADD);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-190,-100); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,190,-100); ObjEffect_SetVertexUV(effect1,1,380,0);
	ObjEffect_SetVertexXY(effect1,2,-190,100); ObjEffect_SetVertexUV(effect1,2,0,200);
	ObjEffect_SetVertexXY(effect1,3,190,100); ObjEffect_SetVertexUV(effect1,3,380,200);
	ObjEffect_SetVertexColor(effect1,0,180,255,255,255); ObjEffect_SetVertexColor(effect1,1,180,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,180,255,255,255); ObjEffect_SetVertexColor(effect1,3,180,255,255,255);
	object1=object1~[effect1];
	}
}

if(time>=60){
	if(xscale1<1){ xscale1+=(xscale1*0.1); }
	if(yscale1<1){ yscale1+=(yscale1*0.2); }
	if(xscale2<1.1){ xscale2+=(xscale2*0.09); }
	if(yscale2<1.2){ yscale2+=(yscale2*0.18); }
	Obj_SetPosition(object1[0],GetX,GetY-30);
	ObjEffect_SetScale(object1[0],xscale1,yscale1);
	ObjEffect_SetVertexColor(object1[0],0,200,0,255,255); ObjEffect_SetVertexColor(object1[0],1,200,0,255,255);
	ObjEffect_SetVertexColor(object1[0],2,200,255,255,255); ObjEffect_SetVertexColor(object1[0],3,200,255,255,255);
	Obj_SetPosition(object1[1],GetX,GetY-30);
	ObjEffect_SetScale(object1[1],xscale2+0.1*cos(time*2),yscale2+0.2*cos(time*2));
	ObjEffect_SetVertexColor(object1[1],0,200,255,100,255); ObjEffect_SetVertexColor(object1[1],1,200,255,100,255);
	ObjEffect_SetVertexColor(object1[1],2,50,255,100,255); ObjEffect_SetVertexColor(object1[1],3,50,255,100,255);
}



if(GetLife>0){
if(time>300){

if((time+90)%900==0 && time>=60 && phase<4){
	SetColor(255,100,150);
	Concentration01(90);
	SetColor(255,255,255);
	PlaySE(SEfocus);
}
if(time%900==0 && time>=60){ phase+=1; frame=0; }

//====================================================================================================================

if(phase==0 && time==301){
	loop(3){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+100*cos(time+0),GetY+40*sin(time+0));
	Obj_SetAngle(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,9);
	bullet1=bullet1~[shot1];
	}
	loop(3){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+100*cos(time+0),GetY+40*sin(time+0));
	Obj_SetAngle(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,10);
	bullet1=bullet1~[shot1];
	}
}

if(phase>=0 && time>=301){
	Obj_SetPosition(bullet1[0],GetX+100*cos(time+0),GetY+40*sin(time+0));
	Obj_SetPosition(bullet1[1],GetX+100*cos(time+120),GetY+40*sin(time+120));
	Obj_SetPosition(bullet1[2],GetX+100*cos(time+240),GetY+40*sin(time+240));

	Obj_SetAngle(bullet1[0],time+90);
	Obj_SetAngle(bullet1[1],time+210);
	Obj_SetAngle(bullet1[2],time+330);

	Obj_SetPosition(bullet1[3],GetX-70*cos(time+0),GetY+20*sin(time+0));
	Obj_SetPosition(bullet1[4],GetX-70*cos(time+120),GetY+20*sin(time+120));
	Obj_SetPosition(bullet1[5],GetX-70*cos(time+240),GetY+20*sin(time+240));

	Obj_SetAngle(bullet1[3],-time+90);
	Obj_SetAngle(bullet1[4],-time+330);
	Obj_SetAngle(bullet1[5],-time+210);
angle1+=2;
}

if(phase>=0 && time%4==0){
	CreateShot02(Obj_GetX(bullet1[0]),Obj_GetY(bullet1[0]),10,angle1,-0.3,2.5,57,25);
	CreateShot02(Obj_GetX(bullet1[1]),Obj_GetY(bullet1[1]),10,angle1+120,-0.3,2.5,57,25);
	CreateShot02(Obj_GetX(bullet1[2]),Obj_GetY(bullet1[2]),10,angle1+240,-0.3,2.5,57,25);

	CreateShot02(Obj_GetX(bullet1[3]),Obj_GetY(bullet1[3]),10,-angle1+245,-0.3,2.5,58,25);
	CreateShot02(Obj_GetX(bullet1[4]),Obj_GetY(bullet1[4]),10,-angle1+125,-0.3,2.5,58,25);
	CreateShot02(Obj_GetX(bullet1[5]),Obj_GetY(bullet1[5]),10,-angle1+5,-0.3,2.5,58,25);
PlaySE(SEshots4);
usespell=30;
}

//====================================================================================================================

if(phase>=1 && frame==1){
	angle2=GetAngleToPlayer;
	color=rand_int(1,10);
PlaySE(SElaserm3);
}
if(phase>=1 && frame>0 && frame<=20){
	loop(15){
	CreateShot02(GetX,GetY-10,1,angle2,0.05,10,70+color,0);
	angle2+=360/15;
	}
	color+=1;
	if(color>10){ color=1; }
}

if(frame>=90){ frame=0; }

//====================================================================================================================

if(phase>=2 && time%3==0){
	CreateShot02(GetX+15,GetY-45,rand(3,7),-time,-0.1,rand(1.8,2.2),rand_int(100,101),0);
	CreateShot02(GetX+15,GetY-45,rand(3,7),-time+180,-0.1,rand(1.8,2.2),rand_int(100,101),0);
}
if(phase>=2 && time%5==0){ PlaySE(SEmagics5); }

//====================================================================================================================

if(phase>=3 && time%10==0){
let x=0;
	loop(16){
	CreateShot01(GetX,GetY,2,phase2angle,81,0+x);
	CreateShot01(GetX,GetY,2,180+phase2angle,81,16-x);
	phase2angle+=0.6;
	x+=1;
	}
phase2angle+=15.5;
PlaySE(SElaserm2);
}

//====================================================================================================================

if(phase>=4 && (time+0)%30==0){
phase3shift=rand(70,90);
	CreateShot02(minx+hpos1,miny,0,90,0.015,4,rand_int(119,121),20);
	hpos1+=phase3shift;
	if(hpos1>maxx){ hpos1-=maxx+40; }
PlaySE(SEshotb7);
}
if(phase>=4 && (time+15)%30==0){
	CreateShot02(minx+hpos2,miny,0,90,0.015,4,rand_int(119,121),20);
	hpos2+=phase3shift;
	if(hpos2>maxx){ hpos2-=maxx+40; }
PlaySE(SEshotb7);
}

}

//====================================================================================================================

if(time==60){ PlaySE(SEimplode2); }

if(time==180){
	loop(225){
	CreateShot12(cx,cy,rand(-4,4),rand(-4,4),0,0,3,3,rand_int(83,94),0);
	CreateShot12(cx,cy,rand(-4,4),rand(-4,4),0,0,3,3,rand_int(95,106),0);
	}
usespell=-30;
PlaySE(SEexplode2);
}

if(time==299){ DeleteEnemyShot(ALL); }

if(time>=300){
	if((time+180)%480==0){ bgchange1=1; bgchange2=0; bgchanged1=0; }
	if((time+420)%480==0){ bgchange2=1; bgchange1=0; bgchanged2=0; }

	if(bgchange1==1 && bgpicture1<4400){
		if(bgfade1<180){ bgfade1+=5; }
		if(bgfade2>0){ bgfade2-=5; }
		if(bgfade2==0 && bgchanged2==0){ bgpicture2+=384; bgchanged2=1; }
	}
	if(bgchange2==1 && bgpicture2<4400){
		if(bgfade2<180){ bgfade2+=5; }
		if(bgfade1>0){ bgfade1-=5; }
		if(bgfade1==0 && bgchanged1==0){ bgpicture1+=384; bgchanged1=1; }
	}
}


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);
}

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,"Tomoko2"); dispelled=1; }
}

@BackGround{
	if(time>=180){
	SetGraphicRect(0,0,300,300);
	SetGraphicScale(2,2);
	SetRenderState(ALPHA);
	SetTexture(BG2);
	SetAlpha(bgfade);
	SetGraphicAngle(0,0,rand(0,360));
	DrawGraphic(cx,cy);
	}
	if(time>=180 && time<300 && bgfade<130){ bgfade+=5; }
	if(time>=300 && bgfade>0){ bgfade-=5; }

	if(time>=300){
	SetGraphicRect(0+bgpicture1,0,192+bgpicture1,224);
	SetGraphicScale(2,2);
	SetRenderState(ALPHA);
	SetTexture(BG1);
	SetAlpha(bgfade1);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);

	SetGraphicRect(192+bgpicture2,0,384+bgpicture2,224);
	SetGraphicScale(2,2);
	SetRenderState(ALPHA);
	SetTexture(BG1);
	SetAlpha(bgfade2);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
	}
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){
	SetGraphicRect(384,outfit,512,outfit+128);
	}
	if(usespell<=-1){
	SetGraphicRect(512,outfit,640,outfit+128);
	}

	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	if(GetLife>0){ DrawGraphic(GetX,GetY); }
}

@Finalize{
	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}